/**
 * 光源
 */

class LightSource {
  viewer: any;
  pointLight: any;
  spotLight: any;
  directionalLight_v: any;
  directionalLight_h1: any;

  constructor(viewer:any) {
    this.viewer = viewer;
  }
  /**
   * 添加点光源到场景中
   * @param param0 世界坐标
   */
  addPointLightHandler({x,y,z}) {
    const position = new Cesium.Cartesian3(x,y,z)
    const options = {
      color: new Cesium.Color(1, 1, 1, 1), // 光源颜色
      cutoffDistance: 300, // 扩散距离
      decay: 1, // 衰减因子
      intensity: 10, // 光源强度
    }
    this.pointLight = new Cesium.PointLight(position, options)
    this.viewer.scene.addLightSource(this.pointLight)
  }
  /**
   * 删除点光源
   */
  removePointLightHandler() {
    this.viewer.scene.removeLightSource(this.pointLight)
  }

  /**
   * 聚光源设置
   * @param Position 
   * @param TargetPosition 
   */
  addSpotLightHandler(Position:[],TargetPosition:[]) {
    const position = new Cesium.Cartesian3(...Position)
    const targetPosition = new Cesium.Cartesian3(...TargetPosition)
    const options = { 
      color: new Cesium.Color(1, 1, 1, 1), // 光源颜色
      distance: 50, // 光照距离
      decay: 0.5, // 衰减因子
      intensity: 20, // 光源强度
    }
    this.spotLight = new Cesium.SpotLight(position, targetPosition, options)
    this.viewer.scene.addLightSource(this.spotLight)
  }
  /**
   * 删除点光源
   */
  removeSpotLightHandler() {
    this.viewer.scene.removeLightSource(this.spotLight)
  }

  /**
   * 添加平行光源到场景中
   * @param Position1 
   * @param Position 
   */
  addDirectionLightHandler(Position1:[],Position:[]) {
    // 以下为水平光源设置
    const position1 = new Cesium.Cartesian3(...Position1)
    const options1 = { // 水平光源
      intensity: 2, // 光源强度
    }
    this.directionalLight_h1 = new Cesium.DirectionalLight(position1, options1)
    // 以下为垂直光源设置
    const position = new Cesium.Cartesian3(...Position)
    const options = { // 垂直光源
      intensity: 2, // 光源强度
    }
    this.directionalLight_v = new Cesium.DirectionalLight(position, options)
    this.viewer.scene.addLightSource(this.directionalLight_v)
    this.viewer.scene.addLightSource(this.directionalLight_h1)
  }
  /**
   * 删除平行光源
   */
  removeDirectionLightHandler() {
    this.viewer.scene.removeLightSource(this.directionalLight_v)
    this.viewer.scene.removeLightSource(this.directionalLight_h1)
  }
}

export default LightSource;